@@ -62,7 +62,7 @@ android { |
||
62 | 62 |
minifyEnabled false |
63 | 63 |
shrinkResources false |
64 | 64 |
buildConfigField "boolean", "isTestMode", "false" |
65 |
- buildConfigField "boolean", "isJumpLogin", "true" |
|
65 |
+ buildConfigField "boolean", "isJumpLogin", "false" |
|
66 | 66 |
signingConfig signingConfigs.releaseConfig |
67 | 67 |
} |
68 | 68 |
} |
@@ -84,7 +84,6 @@ dependencies { |
||
84 | 84 |
apt 'com.jakewharton:butterknife-compiler:8.2.1' |
85 | 85 |
compile 'com.google.code.gson:gson:2.7' |
86 | 86 |
compile files('libs/universal-image-loader-1.9.4.jar') |
87 |
- compile files('libs/libammsdk.jar') |
|
88 | 87 |
compile files('libs/commons-lang-2.6.jar') |
89 | 88 |
compile files('libs/jcc-bate-0.7.3.jar') |
90 | 89 |
compile 'com.umeng.analytics:analytics:latest.integration' |
@@ -1,5 +1,6 @@ |
||
1 | 1 |
package ai.pai.lensman.login; |
2 | 2 |
|
3 |
+import android.app.Activity; |
|
3 | 4 |
import android.content.Intent; |
4 | 5 |
import android.os.Bundle; |
5 | 6 |
import android.support.v4.app.FragmentActivity; |
@@ -11,11 +12,15 @@ import android.widget.ImageView; |
||
11 | 12 |
import android.widget.TextView; |
12 | 13 |
import android.widget.Toast; |
13 | 14 |
|
15 |
+import com.android.common.utils.LogHelper; |
|
14 | 16 |
import com.android.views.progressbar.ProgressWheel; |
15 | 17 |
|
18 |
+import org.json.JSONObject; |
|
19 |
+ |
|
16 | 20 |
import ai.pai.lensman.R; |
17 | 21 |
import ai.pai.lensman.activities.WebViewActivity; |
18 | 22 |
import ai.pai.lensman.main.MainActivity; |
23 |
+import ai.pai.lensman.qrcode.QRCaptureActivity; |
|
19 | 24 |
import butterknife.BindView; |
20 | 25 |
import butterknife.ButterKnife; |
21 | 26 |
import butterknife.OnClick; |
@@ -26,7 +31,7 @@ public class LoginActivity extends FragmentActivity implements LoginContract.Vie |
||
26 | 31 |
@BindView(R.id.tv_agree_protocol) TextView protocolText; |
27 | 32 |
@BindView(R.id.iv_login_logo) ImageView photoView; |
28 | 33 |
private LoginContract.Presenter presenter; |
29 |
- |
|
34 |
+ private static final int SCAN_WX_LOGIN_CODE = 2000; |
|
30 | 35 |
|
31 | 36 |
@Override |
32 | 37 |
protected void onCreate(Bundle savedInstanceState) { |
@@ -36,7 +41,7 @@ public class LoginActivity extends FragmentActivity implements LoginContract.Vie |
||
36 | 41 |
SpannableString content = new SpannableString(getString(R.string.agree_protocol)); |
37 | 42 |
content.setSpan(new UnderlineSpan(), 6, content.length(), 0); |
38 | 43 |
protocolText.setText(content); |
39 |
- presenter = new LoginPresenter(this,this); |
|
44 |
+ presenter = new LoginPresenter(this); |
|
40 | 45 |
} |
41 | 46 |
|
42 | 47 |
|
@@ -49,11 +54,13 @@ public class LoginActivity extends FragmentActivity implements LoginContract.Vie |
||
49 | 54 |
@Override |
50 | 55 |
protected void onDestroy() { |
51 | 56 |
super.onDestroy(); |
57 |
+ presenter.stop(); |
|
52 | 58 |
} |
53 | 59 |
|
54 | 60 |
@OnClick(R.id.btn_login) |
55 | 61 |
public void login(){ |
56 |
- presenter.login(); |
|
62 |
+ Intent intent = new Intent(this, QRCaptureActivity.class); |
|
63 |
+ startActivityForResult(intent, SCAN_WX_LOGIN_CODE); |
|
57 | 64 |
} |
58 | 65 |
|
59 | 66 |
@OnClick(R.id.tv_agree_protocol) |
@@ -90,4 +97,30 @@ public class LoginActivity extends FragmentActivity implements LoginContract.Vie |
||
90 | 97 |
finish(); |
91 | 98 |
} |
92 | 99 |
|
100 |
+ @Override |
|
101 |
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) { |
|
102 |
+ super.onActivityResult(requestCode,resultCode,data); |
|
103 |
+ if (resultCode == Activity.RESULT_OK) { |
|
104 |
+ if (data == null || data.getStringExtra("info") == null) { |
|
105 |
+ Toast.makeText(this,R.string.scan_login_qr_error,Toast.LENGTH_SHORT).show(); |
|
106 |
+ return; |
|
107 |
+ } |
|
108 |
+ String qrInfo = data.getStringExtra("info"); |
|
109 |
+ if(qrInfo.contains("unionid") && qrInfo.contains("token")){ |
|
110 |
+ String json = qrInfo.replace(""","'"); |
|
111 |
+ LogHelper.d("czy","login scan qrcode = "+json); |
|
112 |
+ try{ |
|
113 |
+ JSONObject jsonObject = new JSONObject(json); |
|
114 |
+ String unionid = jsonObject.getString("unionid"); |
|
115 |
+ String token = jsonObject.getString("token"); |
|
116 |
+ presenter.login(unionid,token); |
|
117 |
+ return; |
|
118 |
+ }catch (Exception e){ |
|
119 |
+ LogHelper.e("czy","login deal qrcode error"+e); |
|
120 |
+ } |
|
121 |
+ } |
|
122 |
+ Toast.makeText(this,R.string.scan_login_qr_error,Toast.LENGTH_SHORT).show(); |
|
123 |
+ } |
|
124 |
+ } |
|
125 |
+ |
|
93 | 126 |
} |
@@ -14,7 +14,7 @@ public class LoginContract { |
||
14 | 14 |
} |
15 | 15 |
|
16 | 16 |
interface Presenter extends BasePresenter{ |
17 |
- void login(); |
|
17 |
+ void login(String unionid, String token); |
|
18 | 18 |
} |
19 | 19 |
|
20 | 20 |
} |
@@ -1,9 +1,9 @@ |
||
1 | 1 |
package ai.pai.lensman.login; |
2 | 2 |
|
3 | 3 |
import android.os.AsyncTask; |
4 |
+import android.text.TextUtils; |
|
4 | 5 |
|
5 | 6 |
import com.android.common.executors.ThreadExecutor; |
6 |
-import com.android.common.utils.LogHelper; |
|
7 | 7 |
|
8 | 8 |
import org.json.JSONObject; |
9 | 9 |
|
@@ -20,183 +20,46 @@ import ai.pai.lensman.utils.UrlContainer; |
||
20 | 20 |
public class LoginInteractor implements BaseInteractor { |
21 | 21 |
|
22 | 22 |
private HttpPostTask loginTask; |
23 |
- private HttpPostTask fetchTokenTask; |
|
24 |
- private HttpPostTask fetchUserInfoTask; |
|
25 | 23 |
private InteractorListener<String> listener; |
26 |
- private static final String APP_ID = "wxf4832536d9dda70a"; |
|
27 |
- private static final String APP_SECRET = "9a2efcae3c6038b5450b0c2ef3187b1f"; |
|
28 |
- private String wxCode; |
|
24 |
+ private String unionid; |
|
25 |
+ private String token; |
|
29 | 26 |
|
30 |
- public LoginInteractor(String wxCode, InteractorListener<String> listener) { |
|
31 |
- this.wxCode = wxCode; |
|
27 |
+ public LoginInteractor(String unionid, String token, InteractorListener<String> listener) { |
|
28 |
+ this.unionid = unionid; |
|
29 |
+ this.token = token; |
|
32 | 30 |
this.listener = listener; |
33 | 31 |
} |
34 | 32 |
|
35 | 33 |
@Override |
36 | 34 |
public void startJob() { |
37 |
- fetchToken(); |
|
38 |
- } |
|
39 |
- |
|
40 |
- @Override |
|
41 |
- public void cancelJob() { |
|
42 |
- cancelJob(loginTask); |
|
43 |
- cancelJob(fetchTokenTask); |
|
44 |
- cancelJob(fetchUserInfoTask); |
|
45 |
- } |
|
46 |
- |
|
47 |
- private void cancelJob(HttpPostTask task) { |
|
48 |
- if (task == null) { |
|
49 |
- return; |
|
50 |
- } |
|
51 |
- if (task.getStatus() == AsyncTask.Status.RUNNING) { |
|
52 |
- task.cancel(true); |
|
53 |
- } |
|
54 |
- } |
|
55 |
- |
|
56 |
- private void fetchToken() { |
|
57 |
- |
|
58 |
- final String tokenUrl = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=" + APP_ID |
|
59 |
- + "&secret=" + APP_SECRET + "&code=" + wxCode + "&grant_type=authorization_code"; |
|
60 |
- LogHelper.d("czy","interactor fetchToken with url = "+tokenUrl); |
|
61 |
- fetchTokenTask = new HttpPostTask(null) { |
|
62 |
- |
|
63 |
- String token; |
|
64 |
- String openId; |
|
65 |
- |
|
66 |
- @Override |
|
67 |
- protected boolean parseResponse(String response) { |
|
68 |
- LogHelper.d("czy","interactor fetchToken parseResponse response = "+response); |
|
69 |
- try { |
|
70 |
- JSONObject json = new JSONObject(response); |
|
71 |
- token = json.getString("access_token"); |
|
72 |
- openId = json.getString("openid"); |
|
73 |
- return true; |
|
74 |
- } catch (Exception e) { |
|
75 |
- e.printStackTrace(); |
|
76 |
- } |
|
77 |
- return false; |
|
78 |
- } |
|
79 |
- |
|
80 |
- @Override |
|
81 |
- protected void onPostSuccess() { |
|
82 |
- super.onPostSuccess(); |
|
83 |
- fetchUserInfo(token, openId); |
|
84 |
- } |
|
85 |
- |
|
86 |
- @Override |
|
87 |
- protected void onPostFail() { |
|
88 |
- super.onPostFail(); |
|
89 |
- } |
|
90 |
- }; |
|
91 |
- fetchTokenTask.executeOnExecutor(ThreadExecutor.getInstance().getExecutor(), tokenUrl); |
|
92 |
- } |
|
93 |
- |
|
94 |
- private void fetchUserInfo(String token, String openId) { |
|
95 |
- |
|
96 |
- String userInfoUrl = "https://api.weixin.qq.com/sns/userinfo?access_token=" + token + "&openid=" + openId; |
|
97 |
- LogHelper.d("czy","interactor fetchUserInfo with url = "+userInfoUrl); |
|
98 |
- fetchUserInfoTask = new HttpPostTask(null) { |
|
99 |
- HashMap<String, String> params; |
|
100 |
- |
|
101 |
- @Override |
|
102 |
- protected boolean parseResponse(String response) { |
|
103 |
- LogHelper.d("czy","interactor fetchUserInfo parseResponse response = "+response); |
|
104 |
- try { |
|
105 |
- JSONObject json = new JSONObject(response); |
|
106 |
- params = new HashMap<>(); |
|
107 |
- params.put("unionid", json.getString("unionid")); |
|
108 |
- params.put("openid", json.getString("openid")); |
|
109 |
- params.put("sex", json.getString("sex")); |
|
110 |
- params.put("nickname", json.getString("nickname")); |
|
111 |
- params.put("headimgurl", json.getString("headimgurl")); |
|
112 |
- params.put("country", json.getString("country")); |
|
113 |
- params.put("province", json.getString("province")); |
|
114 |
- params.put("city", json.getString("city")); |
|
115 |
- return true; |
|
116 |
- } catch (Exception e) { |
|
117 |
- e.printStackTrace(); |
|
118 |
- } |
|
119 |
- return false; |
|
120 |
- } |
|
121 |
- |
|
122 |
- @Override |
|
123 |
- protected void onPostSuccess() { |
|
124 |
- super.onPostSuccess(); |
|
125 |
- wxLogin(params); |
|
126 |
- } |
|
127 |
- |
|
128 |
- @Override |
|
129 |
- protected void onPostFail() { |
|
130 |
- super.onPostFail(); |
|
131 |
- } |
|
132 |
- }; |
|
133 |
- fetchUserInfoTask.executeOnExecutor(ThreadExecutor.getInstance().getExecutor(), userInfoUrl); |
|
134 |
- } |
|
135 |
- |
|
136 |
- private void login() { |
|
137 | 35 |
HashMap<String, String> params = new HashMap<>(); |
138 |
- params.put("username", "chengzhenyu"); |
|
139 |
- params.put("password", "paiai"); |
|
36 |
+ params.put("unionid", unionid); |
|
37 |
+ params.put("token", token); |
|
140 | 38 |
|
141 | 39 |
loginTask = new HttpPostTask(params) { |
142 | 40 |
|
143 | 41 |
String lensmanId; |
144 | 42 |
String message; |
145 |
- |
|
146 |
- @Override |
|
147 |
- protected boolean parseResponse(String response) { |
|
148 |
- try { |
|
149 |
- JSONObject json = new JSONObject(response); |
|
150 |
- int status = json.getInt("status"); |
|
151 |
- if (status == 200) { |
|
152 |
- JSONObject info = json.getJSONObject("data"); |
|
153 |
- lensmanId = info.getString("user_id"); |
|
154 |
- return true; |
|
155 |
- } else { |
|
156 |
- message = json.getString("message"); |
|
157 |
- } |
|
158 |
- } catch (Exception e) { |
|
159 |
- e.printStackTrace(); |
|
160 |
- } |
|
161 |
- return false; |
|
162 |
- } |
|
163 |
- |
|
164 |
- @Override |
|
165 |
- protected void onPostFail() { |
|
166 |
- super.onPostFail(); |
|
167 |
- listener.onInteractFail(message); |
|
168 |
- } |
|
169 |
- |
|
170 |
- @Override |
|
171 |
- protected void onPostSuccess() { |
|
172 |
- super.onPostSuccess(); |
|
173 |
- listener.onInteractSuccess(lensmanId); |
|
174 |
- } |
|
175 |
- }; |
|
176 |
- loginTask.executeOnExecutor(ThreadExecutor.getInstance().getExecutor(), UrlContainer.LOGIN_URL); |
|
177 |
- } |
|
178 |
- |
|
179 |
- private void wxLogin(HashMap<String, String> params) { |
|
180 |
- |
|
181 |
- loginTask = new HttpPostTask(params) { |
|
182 |
- |
|
183 |
- String lensmanId; |
|
184 | 43 |
String userName; |
185 |
- String message; |
|
186 | 44 |
|
187 | 45 |
@Override |
188 | 46 |
protected boolean parseResponse(String response) { |
189 |
- LogHelper.d("czy","interactor wxLogin parseResponse response = "+response); |
|
190 | 47 |
try { |
191 | 48 |
JSONObject json = new JSONObject(response); |
192 | 49 |
int status = json.getInt("status"); |
193 | 50 |
if (status == 200) { |
194 | 51 |
JSONObject info = json.getJSONObject("data"); |
195 | 52 |
lensmanId = info.getString("user_id"); |
196 |
- userName = info.getString("nickname"); |
|
53 |
+ userName = info.getString("name"); |
|
54 |
+ if(TextUtils.isEmpty(userName)){ |
|
55 |
+ userName = info.getString("nickname"); |
|
56 |
+ } |
|
57 |
+ if(TextUtils.isEmpty(userName)){ |
|
58 |
+ userName = info.getString("username"); |
|
59 |
+ } |
|
197 | 60 |
return true; |
198 | 61 |
} else { |
199 |
- message = json.getString("message"); |
|
62 |
+ message = json.getString("description"); |
|
200 | 63 |
} |
201 | 64 |
} catch (Exception e) { |
202 | 65 |
e.printStackTrace(); |
@@ -218,7 +81,22 @@ public class LoginInteractor implements BaseInteractor { |
||
218 | 81 |
Preferences.getInstance().setUserName(userName); |
219 | 82 |
} |
220 | 83 |
}; |
221 |
- loginTask.executeOnExecutor(ThreadExecutor.getInstance().getExecutor(), UrlContainer.WX_LOGIN_URL); |
|
84 |
+ loginTask.executeOnExecutor(ThreadExecutor.getInstance().getExecutor(), UrlContainer.BOX_LENSMAN_LOGIN_URL); |
|
222 | 85 |
} |
223 | 86 |
|
87 |
+ @Override |
|
88 |
+ public void cancelJob() { |
|
89 |
+ cancelJob(loginTask); |
|
90 |
+ } |
|
91 |
+ |
|
92 |
+ private void cancelJob(HttpPostTask task) { |
|
93 |
+ if (task == null) { |
|
94 |
+ return; |
|
95 |
+ } |
|
96 |
+ if (task.getStatus() == AsyncTask.Status.RUNNING) { |
|
97 |
+ task.cancel(true); |
|
98 |
+ } |
|
99 |
+ } |
|
100 |
+ |
|
101 |
+ |
|
224 | 102 |
} |
@@ -1,13 +1,9 @@ |
||
1 | 1 |
package ai.pai.lensman.login; |
2 | 2 |
|
3 |
-import android.content.Context; |
|
4 |
-import android.text.TextUtils; |
|
5 |
- |
|
6 | 3 |
import com.android.common.utils.LogHelper; |
7 |
-import com.tencent.mm.sdk.modelmsg.SendAuth; |
|
8 |
-import com.tencent.mm.sdk.openapi.IWXAPI; |
|
9 |
-import com.tencent.mm.sdk.openapi.WXAPIFactory; |
|
10 | 4 |
|
5 |
+import ai.pai.lensman.App; |
|
6 |
+import ai.pai.lensman.R; |
|
11 | 7 |
import ai.pai.lensman.base.BaseInteractor; |
12 | 8 |
import ai.pai.lensman.db.Preferences; |
13 | 9 |
|
@@ -16,39 +12,24 @@ import ai.pai.lensman.db.Preferences; |
||
16 | 12 |
*/ |
17 | 13 |
public class LoginPresenter implements LoginContract.Presenter,BaseInteractor.InteractorListener<String> { |
18 | 14 |
|
19 |
- private IWXAPI api; |
|
20 |
- private Context context; |
|
21 | 15 |
private LoginContract.View view; |
22 | 16 |
private LoginInteractor interactor; |
23 |
- private static final String APP_ID = "wxf4832536d9dda70a"; |
|
24 | 17 |
|
25 |
- public LoginPresenter(Context context,LoginContract.View view){ |
|
18 |
+ public LoginPresenter(LoginContract.View view){ |
|
26 | 19 |
this.view = view; |
27 |
- this.context = context; |
|
28 |
- api = WXAPIFactory.createWXAPI(context, APP_ID, true); |
|
29 |
- api.registerApp(APP_ID); |
|
30 | 20 |
} |
31 | 21 |
|
32 | 22 |
@Override |
33 |
- public void login() { |
|
23 |
+ public void login(String unionid, String token) { |
|
34 | 24 |
LogHelper.d("czy","presenter login"); |
35 |
- |
|
36 |
- SendAuth.Req req = new SendAuth.Req(); |
|
37 |
- req.scope = "snsapi_userinfo"; |
|
38 |
- req.state = "paiai_for_lensman"; |
|
39 |
- api.sendReq(req); |
|
25 |
+ view.showProgressView(); |
|
26 |
+ interactor = new LoginInteractor(unionid,token,this); |
|
27 |
+ interactor.startJob(); |
|
40 | 28 |
} |
41 | 29 |
|
42 | 30 |
@Override |
43 | 31 |
public void start() { |
44 |
- String wxCode = Preferences.getInstance().getWXCode(); |
|
45 |
- LogHelper.d("czy","presenter start with wx code = "+wxCode); |
|
46 |
- if(!TextUtils.isEmpty(wxCode)){ |
|
47 |
- view.showProgressView(); |
|
48 |
- interactor = new LoginInteractor(wxCode,this); |
|
49 |
- interactor.startJob(); |
|
50 |
- Preferences.getInstance().setWXCode(""); |
|
51 |
- } |
|
32 |
+ |
|
52 | 33 |
} |
53 | 34 |
|
54 | 35 |
@Override |
@@ -62,6 +43,7 @@ public class LoginPresenter implements LoginContract.Presenter,BaseInteractor.In |
||
62 | 43 |
@Override |
63 | 44 |
public void onInteractSuccess(String result) { |
64 | 45 |
view.hideProgressView(); |
46 |
+ view.showLoginHint(App.getAppContext().getString(R.string.login_success)); |
|
65 | 47 |
Preferences.getInstance().setLensManId(result); |
66 | 48 |
view.jumpMain(); |
67 | 49 |
} |
@@ -11,8 +11,6 @@ public class UrlContainer { |
||
11 | 11 |
|
12 | 12 |
public static final String LOGIN_URL = HOST_URL+"login"; |
13 | 13 |
|
14 |
- public static final String SESSION_IDS_CREATE = HOST_URL+"uuid"; |
|
15 |
- |
|
16 | 14 |
/** |
17 | 15 |
* user_id # 用户唯一标识 |
18 | 16 |
* nickname # 用户昵称 |
@@ -71,9 +69,6 @@ public class UrlContainer { |
||
71 | 69 |
|
72 | 70 |
public static final String SERVER_TIME_URL=HOST_URL+"s/server_time"; |
73 | 71 |
|
74 |
- /** |
|
75 |
- * 盒子程序版本信息 |
|
76 |
- */ |
|
77 |
- public static final String BOX_VERSION_URL = HOST_URL+"op/bpversion"; |
|
72 |
+ public static final String BOX_LENSMAN_LOGIN_URL = HOST_URL+"box/loginqr"; |
|
78 | 73 |
|
79 | 74 |
} |
@@ -47,7 +47,7 @@ |
||
47 | 47 |
android:layout_marginBottom="50dp" |
48 | 48 |
android:background="@drawable/login_btn_rounded_rect_bg" |
49 | 49 |
android:gravity="center" |
50 |
- android:text="@string/wx_login" |
|
50 |
+ android:text="@string/wx_scan_login" |
|
51 | 51 |
android:textColor="@color/wx_login_btn_stroke" |
52 | 52 |
android:textSize="18sp" /> |
53 | 53 |
|
@@ -12,6 +12,7 @@ |
||
12 | 12 |
<string name="settings">设置</string> |
13 | 13 |
<string name="scene">场景%d</string> |
14 | 14 |
|
15 |
+ <string name="wx_scan_login">扫描拍爱公众号授权码</string> |
|
15 | 16 |
<string name="wx_login">微信登录</string> |
16 | 17 |
<string name="agree_protocol">已阅读并同意<u>拍爱用户协议</u></string> |
17 | 18 |
|
@@ -143,4 +144,6 @@ |
||
143 | 144 |
<string name="usb_permission_denied">请检查设备是否已开放root权限</string> |
144 | 145 |
|
145 | 146 |
<string name="sdcard_error">保存照片失败,请检查手机存储卡</string> |
147 |
+ |
|
148 |
+ <string name="scan_login_qr_error">扫描授权码失败</string> |
|
146 | 149 |
</resources> |